#include <cstdio>
#include <algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int Find_Father(int);
void bing(int, int);

const int N = 30010;
int n, m;
int Father[N];

int Find_Father(int x)
{
	return Father[x] == x ? x : Father[x] = Find_Father(Father[x]);
}

void bing(int a, int b)
{
	int fa = Find_Father(a), fb = Find_Father(b);
	Father[fb] = fa;
	return ;
}


int main()
{
	read(n);read(m);
	for (int i = 1; i <= n; i++) 
		Father[i] = i;

	int num, k, h;
	for (int i = 1; i <= m; i++) 
	{
		read(num);read(h);
		for (int j = 2; j <= num; j++) 
		{
			read(k);
			bing(h,k);
		}
	}

	int f = Find_Father(0), ans = 0;

	for (int i =  0; i <= n; i++) 
	{
		if(f == Find_Father(i))
			ans++;
	}

	printf("%d",ans);

	return 0;
}
